<template>
  <div class="detail-logistics" v-if="logistics">
    <p>
      <span>{{logistics.list[0].time}}</span>
      <span>{{logistics.list[0].text}}</span>
    </p>
    <a @click="handlerLogistics(order)" href="javascript:;">查看物流</a>
  </div>
  <!-- 查看物流信息组件 -->
  <OrderLogistics ref="orderLogisticslTag" />
</template>

<script>
import { ref } from 'vue'
import { logisticsOrder } from '@/api/order'
import OrderLogistics from './order-logistics.vue'
import { useLogistics } from '../index.vue'
export default {
  name: 'DetailLogistics',
  components: {
    OrderLogistics
  },
  props: {
    order: {
      type: Object,
      default: () => ({})
    }
  },
  async setup (props) {
    // 物流信息对象
    const logistics = ref(null)
    // 模拟真实网络环境下的延迟加载
    const $sleep = () => new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve()
      }, 2000)
    })
    await $sleep()
    const data = await logisticsOrder(props.order.id)
    logistics.value = data.result
    return { logistics, ...useLogistics() }
  }
}
</script>

<style lang="less" scoped>
.detail-logistics {
  height: 50px;
  display: flex;
  align-items: center;
  padding: 0 30px;
  background-color: #f5f5f5;
  margin: 30px 50px 0;
  > p {
    flex: 1;
    span {
      color: #999;
      &:first-child {
        margin-right: 30px;
      }
    }
  }
  > a {
    color: @xtxColor;
    text-align: center;
  }
}
</style>
